home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxlibs / vatpm051 / readme.txt < prev    next >
Text File  |  1995-05-03  |  21KB  |  551 lines

  1.                             VARMINT'S AUDIO TOOLS (FreeWare)
  2.                              VERSION 0.51  (beta) for Watcom Cv9.5
  3.  
  4.                       Sound Blaster programming library
  5.  
  6. DISCLAIMER
  7.  
  8.   This software and documentation is provided as-is and is not
  9.   garanteed to do or be anything.  Use at your own risk.
  10.  
  11. FOREWORD
  12.  
  13.   A couple of weeks ago I heard about Varmint Audio Tools(VAT) when I
  14.   checked it out I was very impressed that this freeware sound library actually worked
  15.   and did so very well, so I decided it was definately worth porting to Watcom C.
  16.   I would say about 95% of all the code is the same and  Mr Jorgensen really deserves
  17.   most of the credit for this library.
  18.  
  19.  
  20. INTRODUCTION
  21.  
  22.   This version of VAT 0.51 is the first version to be ported to Watcom so it is likely
  23.   to LOTS OF BUGS.  So far this version has only been tested on my ProAudio 
  24.   Spectum 16.  If you have not seen the real mode version of VAT 0.51, I recommend 
  25.   getting it to see how great this library really is.(See below for locations)  I have so far 
  26.   concentrated on getting the sound functions to work,and I have not really worked 
  27.   very hard at getting the timer functions to work, butI still think this is by far the most 
  28.   complete FREEWARE Sound Blaster programming Kit for Watcom.  To see what this 
  29.   library can do, I recommend you start by running   VATDEMO.EXE to all the different 
  30.   sound functions this library supports.
  31.  
  32.            Functions avaliable 
  33.            -All functions use DSP interrupt driven code and use a DMA channel
  34.        -Play WAVE audio files
  35.            -Play MOD audio files (Some bugs here still)
  36.            -Play MIDI audio files 
  37.            -FM instrument player
  38.            -Sound Mixer that give you the ability to play all these files at the same time (WOW)
  39.  
  40.             Functions in the library that don't work yet
  41.             -All timer functions
  42.             -Vsync functions 
  43.  
  44.   In order to compile this library correctly you need to the /zu option.
  45.  
  46.       EXAMPLE
  47.        wcl386.exe /zu sound.c example.c
  48.  
  49.  
  50.  
  51.   If you try this library out or run the sound demo I would love to hear from you about what
  52.   did and didn't work in this library, and if  you have any comments or suggestions on how to
  53.   make the Watcom version run better let me know.  In the coming weeks look for an updated
  54.   version that works better.  Look for these versions to appear at x2ftp.oulu.fi and               mack.rt66.com:/users/smeagol.  I plan to post anouncements in rec.games.programmer.
  55.  
  56.  
  57.  
  58.        Brian Gavin, Grand Rapids MI
  59.        email:  gavinb@ix.netcom.com
  60.  
  61.  
  62. THE REST OF THIS DOCUMENT IS THE ORGINAL FILE THAT CAME WITH THE ORIGINAL VARMIT AUDIO TOOLS MOST OF THE INFORMATION BELOW HOLDS TRUE, BUT BE
  63. AWARE OF THE FUNCTIONS LISTED ABOVE THAT DON'T WORK
  64.  
  65.  
  66.   Varmint's Audio Tools (VAT) is a small Sound Blaster programming Kit.
  67.   It's primary feature is a DSP interrupt driven core that handles
  68.   real-time mixing and playing of digital sounds, background MIDI
  69.   music, and background MOD music.   It supports many FM chip routines,
  70.   input functions for WAVE samples and MIDI music files, true MPU-401
  71.   MIDI output, auto recognition and setup of Sound Blaster compatible
  72.   cards, and  4.5 (adjustable) millisecond clock and microsecond accuracy
  73.   timers. VAT is Freeware and comes with source and example code (Turbo C).
  74.  
  75.   VAT was adapted from Peter Sprenger's SoundX library.  Peter's library
  76.   was the only sound blaster library that I could actually get working
  77.   out of the half dozen or so that I ftp'ed from x2ftp.oulu.fi.  It is
  78.   a pretty nice library, but the documentation is lacking and the code
  79.   still has a few flaws, so I decided to find out how it worked and
  80.   then modify it to fit my needs as a novice Sound Blaster Programmer.
  81.   Peter has given me personal permission to distribute this library and
  82.   I want to offer  my special thanks to him for his effort and the
  83.   information he has provided.
  84.  
  85. SO WHO NEEDS IT?
  86.  
  87.   VAT is intended for any programmer who wants to add sound effects
  88.   and music to their programs quickly and easily.
  89.   Like so many other programmers, I've been very dissappointed by the
  90.   sound library offerings out there.  I have designed VAT to be very easy
  91.   to use and as versatile as possible, and I hope that it is useful to you.
  92.  
  93.   When dealing with routines that run in the background, most programmers
  94.   are concerned about how many CPU processing cycles the routines use up.  
  95.   Here are the numbers that I get on my 486 DX2/66:
  96.  
  97.   Base overhead:  2.1 %
  98.   Midi overhead:  1.0 % (average)
  99.   Sample overhead: 1.0% per sample
  100.  
  101.   So, let's say that your program is playing some midi music and 4 digital
  102.   samples in the background.  The total overhead would be: 2.1% (base) +
  103.   1% (midi) + 4 * 1.0% (samples) = 7.1%.  That means that
  104.   if you were animating some graphics at 30 FPS, it would slow down to
  105.   27.6 FPS.  Pretty acceptable.
  106.  
  107.  
  108. BETA VERSION
  109.  
  110.   This is the beta version of VAT, so it is a little scant on
  111.   documentation, but I have tried to make up for that by commenting
  112.   the code heavily and providing an example program.
  113.  
  114. HOW TO CONTACT THE AUTHOR(S)
  115.  
  116.   Any suggestions or bug reports are very welcome.  (The demo program
  117.   creates the file "survey.txt" to make this process easier you.) Please 
  118.   send them to one of these email addresses:
  119.  
  120.             smeagol@rt66.com
  121.             ejorgensen@rr5.intel.com
  122.  
  123.   Peter Sprenger can be reached at:
  124.  
  125.             Pete@amber.dinoco.de
  126.  
  127.  
  128. FREEWARE (LISCENCING)
  129.  
  130.   VAT is freeware, so you are free to copy and distribute this library
  131.   as much as you like as long as you charge no fee for it's distribution.
  132.   (The exception to this is if VAT is distributed as part of a large
  133.   collection of shareware/freeware packages.) You are NOT restricted, 
  134.   however, from charging money for games or other programs that use 
  135.   VAT to produce sound.  All I ask is that you send me a complimentary 
  136.   copy.  (Peter Sprenger would like one too.)  This helps me as a 
  137.   developer to know who is using my software and for what.  It is also 
  138.   a good way to make friends!
  139.  
  140.   In other words:
  141.  
  142.     Q: Can put any of the programs or example code from VAT into my
  143.        own shareware that I am going to sell for money?
  144.  
  145.     A: Absolutely not.
  146.  
  147.     Q: If I use VAT to generate sounds in my game, can I sell my game
  148.        for money?
  149.  
  150.     A: Yes!  (Please send Eric Jorgensen and Peter Sprenger complimentary
  151.        copies of your game!)
  152.  
  153. FEATURES
  154.  
  155.   - Background DMA digital playback with real time mixing and
  156.     unlimited channels.
  157.   - Background Playing of MIDI music with easy control of tempo and volume.
  158.   - Background Playing of MOD music with easy control of tempo and volume.
  159.   - Routines to access the FM chip.
  160.   - MPU-401 true MIDI output.
  161.   - Vertical retrace checking functions for animators.
  162.   - 4.5 millisecond (adjustable) clock plus microsecond accuracy timers.
  163.   - AUto recognition and setup of Sound Blaster or Sound Blaster
  164.     compatable sound cards.
  165.   - Does not disturb the system clock (does not use int08)
  166.   - Comes with heavily commented source code and demo.
  167.   - Comes with an FM voice editor
  168.  
  169. VARMINT'S HOME FTP SITE
  170.  
  171.   I have a home site for all of my software:
  172.  
  173.       mack.rt66.com:/users/smeagol
  174.  
  175.   Here you can find my other shareware and freeware offerings:
  176.  
  177.     tmkr11.zip          Terrain Maker - A random Terrain generator/
  178.                         editor for the freeware raytracer Persistence
  179.                         of Vision (POV).
  180.  
  181.     vpova10.zip          Varmint's POV animator - A POV scene file parser
  182.                         that allows the inclusion of functions and
  183.                         animation commands.
  184.  
  185.     svgadiag.zip        Free SVGA diagnostic utility
  186.  
  187.     survey_results.txt  Compiled results of a large survey of SVGA cards
  188.                         that I performed in December of 1994.
  189.  
  190. -----------------------------<*>----------------------------------------
  191.  
  192. VOICEED.EXE  - The FM voice editor
  193.  
  194.   This is a simple package to make editing FM voices a little easier
  195.   for you.  To use it, you will need a VGA capable graphics card and a mouse.
  196.   The interface is fairly simple and should be self-explanatory. Here is
  197.   some lame, rudimentary documentation:
  198.  
  199.   To change the name of a voice or a filename, just click on the text and
  200.   the program will let you type in a new name.
  201.  
  202.   To toggle a radio button, just click on it.
  203.  
  204.   To operate a slider, either click and drag the slider tool with the mouse
  205.   or click on the arrows on the sides.  (The arrows move the slider one
  206.   unit.)
  207.  
  208.   Highlighted letters on butons are hot keys.  A button can be accessed
  209.   from the keyboard by pressing the hotkey letter.
  210.  
  211.   Be sure to save the file before you quit the program!
  212.  
  213.  
  214.   More documentation will show up in version 1.0.
  215.  
  216.  
  217. -----------------------------<*>----------------------------------------
  218.  
  219.  
  220.  
  221. USING VARMINT'S AUDIO TOOLS:  A CRASH COURSE
  222.  
  223.   Compiling the source code:
  224.  
  225.     The sound routines are desinged around FAR or HUGE pointers, so
  226.     you need to compile under a large or huge memory model.  If you
  227.     are using Turbo C and you wnat more memore under the debugger,
  228.     you can request more by selecting "Debugger" from the options menu.
  229.  
  230.     Make sure that stack checking is turned OFF.
  231.  
  232.   Starting up the mixing kernel (ie: the sound engine):
  233.  
  234.     #include "sound.h"
  235.  
  236.     main()
  237.     {
  238.       if(SB_Setup()) {
  239.         Go_Varmint();                // THis starts up the background handler
  240.                                     // and enables you to play sounds and
  241.                                     // MIDI music.
  242.         do_some_stuff();
  243.  
  244.         Dropdead_Varmint();          // THis removes Varmint's interrupt and
  245.                                     // puts the regular system clock
  246.                                     // interrupt back.
  247.       }
  248.       else {
  249.         printf("You don't have a sound Blaster.  EGAD!");
  250.       }
  251.     }
  252.  
  253.     ***  IMPORTANT ******  IMPORTANT ******  IMPORTANT ******  IMPORTANT ***
  254.  
  255.     - Do not call Go_Varmint() if SB_Setup() fails.
  256.  
  257.     - If you call Go_Varmint() and your program breaks or crashes before
  258.     Dropdead_Varmint() is called, you should reboot your computer, or
  259.     you might get a system crash next time you run your program.
  260.  
  261.     - If you call Go_Varmint(), you MUST call Dropdead_Varmint() before
  262.     your program exits.  If you don't, you might not be able to run
  263.     your program again without rebooting the system.
  264.  
  265.     - As a general rule, you should only have one Go_Varmint and one
  266.     Dropdead_Varmint() in your code.
  267.  
  268.     ***  IMPORTANT ******  IMPORTANT ******  IMPORTANT ******  IMPORTANT ***
  269.  
  270.  
  271.   Playing Sounds
  272.  
  273.     Once Go_Varmint has been called, you are free to play sounds.  You will
  274.     first need to load the sound (8bit mono WAVE format.) and stick
  275.     it onto a type SAMPLE pointer.  
  276.  
  277.     (You can use the function SetRate() to change the playback rate of the
  278.     sounds.  Also see information about the global variables vclock and 
  279.     dma_bufferlen below.)
  280.  
  281.     void somefunc()
  282.     {
  283.       unsigned char huge *sounddata;
  284.       unsigned long int sound_length;
  285.  
  286.       sounddata = loadwave("shwoop.wav",&sound_length);
  287.       if(!sounddata) {
  288.         printf("Error loading wave.");
  289.         exit(0);
  290.       }
  291.  
  292.       playsound(sounddata,sound_length);
  293.     }
  294.  
  295.     You only have to load the sound once, and since playsound() handles 
  296.     things intelligently, you can call playsound()
  297.     as many times with as many different samples as you want without  
  298.     having to worry about conflicts. 
  299.     
  300.     playsound() will not cause any problems if Go_Varmint() has not 
  301.     been called, but it won't play anything, either. :)
  302.  
  303.   Playing MIDI files
  304.  
  305.     To play a midi file, you don't actually call a funtion, but you
  306.     instead set values to a few global variables.
  307.  
  308.     unsigned char  inst[1][11] = { 0x03,0x01,0x80,0x80,0xF7,0xF7,
  309.                                   0x13,0x13,0x02,0x01,0x03},  // Harpsichord
  310.  
  311.     void mididemo(void)
  312.     {
  313.       int i,j,k,err;
  314.       char *errstring[256],r=0;
  315.       static MIDI *bach  = NULL;
  316.  
  317.       FM_Reset();
  318.  
  319.       for(i = 0 ; i < 9; i++) {           // Set up FM voices
  320.         FM_SetVol(i,0);
  321.         FM_SetVoice ( i,inst[0]) ;
  322.       }
  323.  
  324.                                           // load a midi file
  325.       err = ReadMidi("bach.mid",&bach,errstring);
  326.       if(err) {
  327.         printf("MIDI read ERROR: %s\n",errstring);
  328.         printf("Exit?\n");
  329.         r = getch();
  330.         if(r != 'n') exit(1);
  331.       }
  332.  
  333.       midi_data = bach;                   // assign the music
  334.       midi_reset = TRUE;                  // reset internal midi variables
  335.       midi_on = TRUE;                      // Turn on the midi player now!
  336.     }
  337.  
  338.     You can adjust the volume by changing the value of the global
  339.     variable "music_volume". (Min = 0, max = 63, default = 50)
  340.  
  341.     You can adjust the tempo by changing the value of the global
  342.     variable "midi_usertempo".  (default = 2.0,  0 = fastest
  343.     50.0 = come back wednesday) See also information about dma_bufferlen
  344.     and midi_tempoadjust below.
  345.  
  346.     Voices can be altered while a song is playing without any problems.
  347.  
  348.     You can turn on MPU-401 output by setting the value of the global
  349.     variable midi_mpuout to TRUE;
  350.  
  351.   Playing MOD files
  352.  
  353.     Playing a MOD file is almost exactly the same as playing a MIDI file.
  354.  
  355.     To play a MOD file, you don't actually call a funtion, but you
  356.     instead set values to a few global variables.
  357.  
  358.     void moddemo(void)
  359.     {
  360.       int i,j,k,err;
  361.       char *errstring[256],r=0;
  362.       static MOD *modfile  = NULL;
  363.  
  364.                                            // load a mod file
  365.       err = ReadMidi("noname.mid",&bach,errstring);
  366.       if(err) {
  367.         printf("MOD read ERROR\n");
  368.         exit(1);
  369.       }
  370.  
  371.       mod_data = bach;                   // assign the music
  372.       mod_reset = TRUE;                  // reset internal MOD variables
  373.       mod_on = TRUE;                     // Turn on the MOD player now!
  374.     }
  375.  
  376.     You can adjust the volume by changing the value of the global
  377.     variable "mod_volume". (Min =16, max = 0, default = 7)
  378.  
  379.     You can adjust the tempo by changing the value of the global
  380.     variable "mod_bytespertick".  (default = 220,  60* = fastest
  381.     500 = come back wednesday) See also information about dma_bufferlen
  382.     and midi_tempoadjust below. (* mod_bytespertick can never be
  383.     smaller than dma_bufferlen.  If it is, mod_on will automatically
  384.     be set to false.)
  385.  
  386.   Using VarmintVSync
  387.  
  388.     VarmintVSync() is a function that can check for a vertical retrace
  389.     without being disturbed by the mixing kernel.  It is designed to
  390.     be used by game animators who time their animations by the vertical
  391.     retrace signal.
  392.  
  393.     void animate()
  394.     {
  395.       ...
  396.  
  397.       sync_on = TRUE;                     
  398.  
  399.       while(foo) {
  400.  
  401.         prepare_graphics();               
  402.  
  403.         VarmintVSync();                   // Wait for next retrace
  404.  
  405.         dump_graphics();
  406.       }
  407.     }
  408.  
  409.     sync_on is a global variable that use use to turn on/off vsync
  410.     checking within the mixing kernel.  Turning this off will cause 
  411.     VarmintVSync to behave like a normal vsync  function, and will 
  412.     reduce the CPU overhead by a tiny bit.
  413.  
  414.     
  415.   Miscellaneous Functions and Variables
  416.  
  417.     extern unsigned _stklen          
  418.       I was getting random reports with older version of the library
  419.       of stack overflow errors and system crashes.  I turned on the stack
  420.       checking option on my compiler, and what do you know, the sound
  421.       code started crashing!  I traced the problem to sb_int().  It only
  422.       crashes when it tries to call external functions.  By all appearances,
  423.       I should only need about 1K of stack space, but I had to increase 
  424.       it to 8K to make the problem go away.  If you can explain this
  425.       behavior, by all means, drop me a note!
  426.  
  427.     void SetRate(int rate)
  428.       This function allows you to dynamically change the playback rate.
  429.       Changing setrate will affect the frequency at which vclock is
  430.       incremented.  It will also affect the midi playback tempo.
  431.  
  432.     long int vclock
  433.       This isn't a function.  It is a global varibable that contains
  434.       the current clock tick from the sound handler.  The frequency
  435.       at which is incremented can be calculated like this:
  436.  
  437.           sample_rate / dma_bufferlen
  438.  
  439.       With library default settings, this is every 5.45 milliseconds.
  440.  
  441.     long int dma_bufferlen
  442.       This is another global variable, and it controls the size of
  443.       the DMA mixing buffer.  The default is 60 bytes.  If you want to 
  444.       change this number, you should do so before you call SB_Setup()
  445.       By making this number bigger, you will lower the frequency that
  446.       sb_int is called.  You might want to do this if you think the sound
  447.       routines are messing up some other time sensitive functions 
  448.       those that look for the VGA verticle sync.
  449.  
  450.       If you increase dma_bufferlen, bbe sure to increase midi_tempoadjust 
  451.       by the same ratio, or your midi flies will play at the wrong speed.
  452.  
  453.     float midi_tempoadjust
  454.       This global variable changes the midi tempo by reducing the delay time
  455.       between notes.  The default value for this is 2.0. Bigger numbers
  456.       make the music faster.  You should only have to mess with this number
  457.       if you cahnge the value of dma_bufferlen.
  458.  
  459.     WORD DSP_overhead
  460.       This is another global variable.  It always holds the number of
  461.       clock ticks that elapsed during the most previous sound handler
  462.       interrupt.  Each clock tick is 0.858 microseconds.  Setting
  463.       DSP_overhead to 0 will turn DSP overhead checking off. Giving
  464.       it any kind of a value will turn it back on again.
  465.  
  466.     void timer_on()
  467.     WORD timer_off()
  468.       This a hyperaccurate suit of timer funcs.  Start by calling
  469.       timer_on() and the read the result from timer_off().  Each tick
  470.       is about 0.838 *micro*seconds.  These functions are only good
  471.       for measuring times shorter than about 50 milliseconds.
  472.  
  473.     msdelay(int milliseconds)
  474.       Standard millisecond delay function.  I mention this becasue VAT
  475.       seems to cause problems with the delay() function included with
  476.       Turbo C.
  477.  
  478.     void load_instruments(char *filename,BYTE inst[128][11])
  479.       This loads 128 instruments definitions from a file of your choosing.
  480.  
  481.     void freemidi(MIDI *m)
  482.     void freemod(MOD *m)
  483.       These functions are for convenience.  They free all the internal
  484.       data structures and then the parent structure itself.
  485.  
  486.   A FEW WORDS ABOUT MIDI
  487.  
  488.     The MIDI standard specifies that a midi compliant instument needs to
  489.     have something like 24 voices available for playback.  Since the
  490.     Sound blaster FM chip only offers 9 (even less if you implement
  491.     percussion), You should be wary of playing midi files that play more
  492.     than 9 voices simultaneously.  Here are some general tips:
  493.  
  494.       - use midi files that have only 5-6 voices max.
  495.  
  496.       - Unless you implement rythm voices, chop off the rythm track
  497.         with a midi editor.
  498.  
  499. COMING SOON
  500.  
  501.   Better docs!
  502.  
  503.   New functions!  
  504.     MOD support
  505.     OPL MIDI ouput
  506.  
  507.   Cooler Demo!
  508.  
  509.  
  510.  
  511. -----------------------------<*>----------------------------------------
  512.  
  513.  
  514.  
  515. Here is a note from Peter Sprenger's SoundX library: ------------------
  516.  
  517.                  Pete@amber.dinoco.de
  518.  
  519.  
  520. Why I made this library: I was myself in a search of a good library
  521. for soundblaster programming. What I encountered was the SBF, that
  522. was a nice idea but written in a such a hurry, that it was still
  523. useless. I has still bugs, too. Some other packages looked
  524. interesting but are quite expensive. I just bought the original SBK
  525. from Creative Labs and was disappointed. It was expensive and bad!
  526. In their design I lost control of Timer 0, that I needed for my other
  527. programming.
  528. So I decided to make a good freeware soundblaster bibleothek. Up to
  529. now I spent about 200 hours working time in this project. It is my
  530. hope that their will be other people who make freeware that can be
  531. used. If every programmer would spend about 100 hours for freeware in
  532. the lifetime, not everybody had to reinvent the wheel again. Look at
  533. the guys from GNU and OSF they are doing a great job!
  534.  
  535. If you can use this routines use them! There must be non false shame.
  536. I wrote this stuff that not everybody has to write his own routines.
  537. But it would be nice, that when you make something commercial with my
  538. routines, that you send me a copy of your project or send me some bucks,
  539. just enough for pizza and coke to support my night programming sessions.
  540. If you send me nothing, ok. But USE the stuff, if you can need it!
  541.  
  542. Have fun with SoundX,
  543.  
  544.       Pete
  545.  
  546. Germany, 27-Jun-93
  547.  
  548. ------------------------------------------------------------------------
  549.  
  550.  
  551.